<template>
	<view class="index">
<tn-nav-bar fixed :bottomShadow="false">商家中心</tn-nav-bar>
  <block v-if="shop.address">
		<view class="head" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view class="tit">{{shop.nick}}</view>
			<view class="jiu">
			
				<view class="jiu_01 " @click="shouru()">

					<view class="tn-icon-order" style="font-size: 40px;"></view>
					<view class="text-lg">订单管理</view>

				</view>
				<view class="jiu_01 "  @click="shangpin()">
				
					<view class="tn-icon-shop" style="font-size: 40px;"></view>
					<view class="text-lg">商品管理</view>
				
				</view>
				<view class="jiu_01 "  @click="tixianquy()">
				
					<view class="tn-icon-money" style="font-size: 40px;"></view>
					<view class="text-lg">提现记录</view>
				
				</view>
				<view class="jiu_01 "  @click="tui()">
				
					<view class="tn-icon-close" style="font-size: 40px;"></view>
					<view class="text-lg">退出登录</view>
				
				</view>
			</view>
		</view>
		
		<view class="" >
			<view class="tn-flex tn-flex-row-between">
				<view class="justify-content-item tn-margin  tn-text-xl">
					保证金：{{shop.save_money}}元
				</view>
				<view class="justify-content-item tn-margin tn-text-lg tn-color-grey"
					>
				<tn-button @click="baozhengjian()" v-if="shop.save_money_pay==0"  :shadow="true" backgroundColor="#27a26c"  shape="round" padding="20rpx 20rpx" width="150rpx" shadow fontBold >
				  <text class="tn-color-white">缴纳</text>
				</tn-button>
				
				<text v-if="shop.save_money_pay==1" >已缴纳</text>
				</view>
			</view>
		</view>
		<view class="BH"></view>
		<view class="more">
			<view class='mo'>
				<view class='mo_01 text-lg'>{{shop.title}}</view>

			</view>
		</view>

		<view class="tn-flex tn-flex-row-between bg-white tn-padding-sm">
			<view class="tn-padding-sm tn-main-gradient-blue--light" style="width: 50%;">
				<view class="padding radius text-center light bg-green">
					<view class=" "><text style="margin-right: 10rpx;">未提现</text> 
					<tn-button @click="tixian_anniu=1;istixian=false" v-if="shop.save_money_pay==1"  :shadow="true" backgroundColor="#27a26c"  shape="round" padding="0rpx 8rpx" width="100rpx" shadow fontBold >
				  <text class="tn-color-white">提现</text>
				</tn-button>
				
				</view>
					<view class="tn-margin-top-sm tn-text-xxl">￥{{shop.money}}</view>
				</view>
			</view>
			<view class="tn-padding-sm tn-main-gradient-blue--light" style="width: 50%;">
				<view class="padding radius text-center light bg-yellow">
					<view class="">已提现</view>
					<view class="tn-margin-top-sm tn-text-xxl">￥{{shop.yitixian}}</view>
				</view>
			</view>
				</view>
				<view class="tn-flex tn-flex-row-between bg-white tn-padding-sm" >
			<view class="tn-padding-sm tn-main-gradient-blue--light" style="width: 50%;">
				<view class="padding radius text-center light bg-red">
					<view class="">总订单数</view>
					<view class="tn-margin-top-sm  tn-text-xxl">{{shop.dingdan}}单</view>
				</view>
			</view>
			<view class="tn-padding-sm tn-main-gradient-blue--light" style="width: 50%;">
				<view class="padding radius text-center light bg-orange">
					<view class="">总收入</view>
					<view class="tn-margin-top-sm tn-text-xxl">￥{{shop.yitixian+shop.money}}</view>
				</view>
			</view>
		</view>
	<view class="BH"></view>
		<view class="tn-padding bg-w" style="" v-if="tixian_anniu==1">
			<view v-if="!istixian">
				<view class="bg-w bdr16 box-shadow tn-margin flex space alcenter">
					<view class="flex alcenter">

						<view class="ml20 ft16 text-info">当前可提现余额</view>
					</view>
					<view class="tn-text-lg tn-color-red ftw600 text-default">¥{{ shop.money }}</view>
				</view>

				<view class="tn-margin bg-w bdr16 box-shadow pd40">
					<view class="ft16 text-info">提现额度</view>
					<view class="flex alcenter mt30">
						<input type="text" placeholder="请输入金额" style="width:300rpx;height: 80rpx;background-image: repeating-linear-gradient(45deg, #d7d7d7, #d9d9d9);
    color: #000000;" v-model="money" class="tn-text-lg ftw600 tn-padding-left" />
					</view>
				</view>
				<view class="tn-margin flex ft14  text-notice">最少提现{{ shop.tixian_jine_partner }}元；1-7个工作日到你签约时提供的银行卡。如需要修改提现账号请联系客服！
				</view>


				<view class="tn-flex ">
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center" @click="tixianpass()">
						<tn-button backgroundColor="#00aa7f" padding="40rpx 0" width="100%" shadow fontBold>
							<text class="tn-color-black">确认提现</text>

						</tn-button>
					</view>
				</view>
			</view>

			<view v-if="istixian">
				<view class="tn-margin bg-w">
					<view class="text-center">
					</view>
					<view class="text-center ft18 text-default tn-margin">提现申请成功</view>

					<view class="text-center ft16 text-info tn-margin">我们会在1-7个工作日内审核并完成转账</view>

				
				</view>
			</view>
		</view>


	
	

</block>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				tixian_anniu:0,
				istixian: false,
				money: '',
				tancl: false,
				shop: []
			}
		},

		onShow() {
			if (!uni.getStorageSync('honginfo').id) {
					uni.redirectTo({
						url: '/homeMixinPages/hongniang/login'
					})
					return
				}else{
					this.info()
				}
		

		},
	
		methods: {
			async tixianpass() {
			
				let that = this
				if (!this.money) {
					this.msg('请输入提现金额');
					return;
				}
				if (this.money > this.shop.money) {
					this.msg('不能超过你的余额哦！');
					return;
				}

				if (this.money < this.shop.tixian_jine_partner) {
					this.msg('最低提现额度:' + this.shop.tixian_jine_partner);
					return;
				}

				let result = await that.$request({
					loading: 1,
					method: 'post',
					url: '/chat/partner/dotixian',
					data: {
						money:this.money					
					}
				});
				if (result.statusCode == 200) {
					if (result.data.code == 200) {
						uni.hideLoading()
						this.istixian = true;
						this.info()

					} else {
						this.msg(result.data.msg)
					}

				}			
			},
			
			
			async baozhengjian(payType) {
				let that = this;
				// #ifdef APP
				if (payType == 'alipay') {
					var url = '/chat/shop/baozheng_alipay';
				} else {
					var url = '/chat/shop/baozheng_wxpay';
				}
			
				let result = await that.$request({
					loading: 1,
					method: 'post',
					url: url,
					data: {
						id:this.shop.id
					}
				});
			
				
				
				if (result.statusCode == 200) {
					if (result.data.code == 200) {
			
						uni.requestPayment({
							provider: payType,
							orderInfo: result.data.data, //支付宝订单数据
							success: function(res) {
								if (res.errMsg == 'requestPayment:ok') {	
								
							that.payok()
								
								//uni.navigateBack()
								} else {
									console.log('fail:' + JSON.stringify(res));
								}
							},
							fail: function(err) {
								console.log(err)
							}
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: result.data.msg
						});
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: that.$errorMsg
					});
				}
			
				// #endif
			
			
				// #ifdef MP
				//微信小程序
			
				let result = await that.$request({
					loading: 1,
					method: 'post',
					url: '/chat/shop/baozheng_xcx',
					data: {
						id:this.shop.id	
					}
				});
			
			
				if (result.statusCode == 200) {
					if (result.data.code == 200) {	
					 let paycanshu=JSON.parse(result.data.data.pay)	
							uni.requestPayment({
							provider: 'wxpay',
							timeStamp:paycanshu.timeStamp,
							nonceStr: paycanshu.nonceStr,
							package: paycanshu.package,
							signType: 'MD5',
							paySign: paycanshu.paySign,
							success: function(res) {
					that.payok()
						
							},
			
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: result.data.msg
						});
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: that.$errorMsg
					});
				}
			
				// #endif
				
				// #ifdef H5
				//微信公众号
							
				let ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/micromessenger/i) == 'micromessenger') {					
				}else{
					this.msg('请到微信里打开才能支付！复制网址到微信访问吧'+ua.match(/micromessenger/i))
					//return
				}
				
				let result = await that.$request({
					loading: 1,
					method: 'post',
					url: '/chat/shop/baozheng_h5',
					data: {
					id:this.shop.id	
					}
				});
				
				
				if (result.statusCode == 200) {
					if (result.data.code == 200) {
						
						let paycanshu = result.data.data
							
				
					
					//、、、、、
							 WeixinJSBridge.invoke(
							            'getBrandWCPayRequest', {
							                "appId":paycanshu.appId, //公众号名称，由商户传入
							                "timeStamp":paycanshu.timeStamp, //时间戳     
							                "nonceStr":paycanshu.nonceStr, //随机串     
							                "package": paycanshu.package,
							                "signType":paycanshu.signType, //微信签名方式：     
							                "paySign":paycanshu.paySign //微信签名 
							            },
							            function(ress) {
							                if (ress.err_msg == "get_brand_wcpay_request:ok") {
							        that.payok()
							         
							                } else if (ress.err_msg == "get_brand_wcpay_request:cancel") {
							                    uni.showToast({
							                        icon: "none",
							                        title: "'已取消支付"
							                    })
							                } else {
							                    uni.showToast({
							                        icon: "none",
							                        title: "支付失败"
							                    })
							                }
							            }
							        );			
					//、、、
										
					} else {
						uni.showToast({
							icon: 'none',
							title: result.data.msg
						});
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: that.$errorMsg
					});
				}
				
				// #endif
				
			},
			
			payok(){
				let that = this
				uni.showModal({
					title: '提示',
					content: '保证金缴纳成功',
					confirmText: '确定',
					showCancel:false,
					success: function(res) {
						if (res.confirm) {
							that.info()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			async info() {
				let that = this

				if (!uni.getStorageSync('bizData').id) {
					uni.redirectTo({
						url: '/tuanPages/biz/login'
					})
					return
				}

				let result = await that.$request({
					loading: 0,
					method: 'post',
					url: '/chat/partner/index',
					data: {
						
					}
				});
				if (result.statusCode == 200) {
					if (result.data.code == 200) {
				
						this.shop = result.data.data
						
						if (this.shop.password!==uni.getStorageSync('bizData').password){
						
							uni.showModal({
								title: '提示',
								content: '密码更换已掉线,请重新登录',
								confirmText: '确定',
								showCancel:false,
								success: function(res) {
									if (res.confirm) {
											uni.setStorageSync('ptoken', '');
											uni.setStorageSync('bizData', []);
										uni.redirectTo({
											url: '/tuanPages/biz/index'
										})
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
						
						//uni.hideLoading()

					} else {
						this.msg(result.data.msg)
					}
				}



			},
			//弹窗
			tan() {
				this.tancl = !this.tancl
			},
			//扫码
			shao() {
				this.info()
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						uni.navigateTo({
							url: '/shopPages/biz/yanzheng?code=' + res.result
						})
					}
				});
			},

			shouru() {
				this.info()
				uni.navigateTo({
					url: '/shopPages/biz/shouru'
				})
			},
			tixian() {
				this.info()
				uni.navigateTo({
					url: '/shopPages/biz/caiwu'
				})
			},
			tixianquy() {
				this.info()
				uni.navigateTo({
					url: '/shopPages/biz/caiwu'
				})
			},
			shangpin() {
				
				
				//this.info()
					if (this.shop.save_money_pay==0){
						this.msg('请先缴纳保证金')
						return
					}
				
				uni.navigateTo({
					url: '/shopPages/biz/shangpin'
				})
			},
			
			qutixian() {
				this.info()
				uni.navigateTo({
					url: '/shopPages/biz/tixian'
				})
			},


			tui() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					confirmText: '确定',
					success: function(res) {
						if (res.confirm) {					
					uni.setStorageSync('ptoken', '');
					uni.setStorageSync('bizData', []);
					uni.navigateBack();
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
			},
			yanzheng() {
				this.info()
				uni.navigateTo({
					url: '/tuanPages/biz/yanzheng'
				})
			}
		}
	}
</script>


<style lang="scss">
	.footerfixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 999;
	}

	.index {
		background: #fff;

		.H50 {
			height: 50px;
		}

		.head {
			background: linear-gradient(to bottom, #52c693, #27a26c);
			text-align: center;
			padding: 20px 0 10px;
			color: #fff;
			font-size: 16px;
		}

		.jiu {
			font-size: 16px;
			padding: 10px;
			display: flex;
			flex-wrap: wrap;
			color: #fff;
		}

		.form_button {
			margin-top: 98rpx;
			background-color: #88DFBA;
			border-radius: 8rpx;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 36rpx;
			color: #FFFFFF;
		}

		.jiu_01 {
			width: 25%;
			text-align: center;
			padding: 15px 10px 15px;
			box-sizing: border-box;
			font-size: 12px;
		}

		.jiu_01 image {
			width: 32px;
			height: 32px;
			margin-bottom: 10px;
		}

		.mo {
			padding: 10px;
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #f0f0f0;
			line-height: 20px;
		}

		.mo_01 {
			padding-left: 10px;
			box-sizing: border-box;
			width: 80%;
			height: 20px;
			overflow: hidden;
			border-left: 3px solid #EC521B;

			font-weight: bold;
		}

		.mo_01 span {
			color: #8E8E8E;
			font-weight: 100;
			font-size: 12px;
			padding-left: 10px;
		}

		.mo_02 {
			color: #D6D6D6;
		}

		.shuju {
			display: flex;
			flex-wrap: wrap;
		}

		.shuju_01 {
			width: 50%;
			text-align: center;
			padding: 18px 10px;
			box-sizing: border-box;
			font-size: 14px;
			line-height: 25px;
			font-size: 14px;
			border-right: 1px solid #f0f0f0;
			border-bottom: 1px solid #f0f0f0;
		}

		.shuju_01_s {
			color: #EB511B;
			font-weight: 800;
			font-size: 16px;
		}

		.no {
			border-right: none;
		}

		.BH {
			background-color: #F1F1F1;
			height: 5px;
		}

		.six {
			padding: 10px;
			display: flex;
			flex-wrap: wrap;
		}

		.list_01 {
			padding: 15px 10px 8px;
			border-bottom: 1px solid #F4F4F4;
			font-size: 12px;
		}
	}
</style>